<template>
	<div class="mainWrapper Adjustment">
		<el-breadcrumb separator="/">
			<el-breadcrumb-item :to="{ path: '/' }">
				<i class="lh lh-caiwu fw_100"></i>
			</el-breadcrumb-item>
			<el-breadcrumb-item>账单结算</el-breadcrumb-item>
			<el-breadcrumb-item>任务调账</el-breadcrumb-item>
		</el-breadcrumb>

		<div class="content_Box box-shadow">
			<div class="py_5 px_10">
				<el-row>
					<el-col :span="4">
						<el-button type="default" class="fl" @click="downloadOrder()" round size="mini">导出</el-button>
						<el-button type="success" @click="goToAdd()" round size="mini">新增</el-button>
					</el-col>
					<el-col :span="20" class="fr">
						<el-form :inline="true" class="form-inline fr" @keyup.enter.native="shearchBtn()">
							<el-form-item>
								<el-input v-model="task_sn" placeholder="任务编号"></el-input>
							</el-form-item>
							<!-- 代理商 -->
							<lh-agent-list @sendValue="setValue" :reset="agent_reset"></lh-agent-list>
							<el-form-item>
								<el-select class="w_110" v-model="city_val" placeholder="请选择城市" @change="changeCity">
									<el-option
										v-for="item in cityList"
										:key="item.id"
										:label="item.name"
										:value="`${item.id}|${item.name}`"
									></el-option>
								</el-select>
							</el-form-item>
							<el-form-item>
								<el-select v-model="s_area_arr" multiple collapse-tags placeholder="商圈">
									<el-button
										size="mini"
										type="primary"
										class="round-right all-area"
										@click="selectAllArea()"
										native-type="button"
										>{{ areaStatus ? '全选' : '取消全选' }}</el-button
									>
									<el-option
										v-for="item in areaList"
										:key="item.id"
										:label="item.area_name"
										:value="`${item.id}|${item.area_name}`"
									></el-option>
								</el-select>
							</el-form-item>
							<el-form-item>
								<el-autocomplete
									size="mini"
									class="w_150"
									v-model="shop_name"
									:fetch-suggestions="querySearch"
									placeholder="请选择店铺名称"
									:trigger-on-focus="true"
									@select="handleSelect"
									clearable
								></el-autocomplete>
							</el-form-item>
							<!-- <el-form-item>
								<el-input v-model="staff_name" placeholder="接单人"></el-input>
							</el-form-item> -->
							<el-form-item class="w_100">
								<el-input v-model="staff_name" placeholder="接单人"></el-input>
							</el-form-item>
							<el-form-item prop="datetime1">
								<el-form-item prop="date1">
									<el-date-picker
										class="w_120i"
										v-model="start_time"
										type="date"
										value-format="yyyy-MM-dd"
										placeholder="任务开始时间"
									>
									</el-date-picker>
								</el-form-item> </el-form-item
							>~
							<el-form-item prop="datetime2">
								<el-form-item prop="date2">
									<el-date-picker
										class="w_120i"
										v-model="end_time"
										type="date"
										value-format="yyyy-MM-dd"
										placeholder="任务结束时间"
									>
									</el-date-picker>
								</el-form-item>
							</el-form-item>
							<el-button size="mini" type="primary" class="round-right" native-type="button" @click="shearchBtn"
								>搜索</el-button
							>
							<el-button size="mini" round @click="resetBtn">重置</el-button>
						</el-form>
					</el-col>
				</el-row>
			</div>

			<div class="tableMaxBox">
				<template>
					<!-- 表格部分 -->
					<el-table :data="adjustmentList" stripe>
						<el-table-column type="index" prop="id" label="序号" width="50px" align="center"></el-table-column>
						<el-table-column prop="task_sn" label="任务编号" width="130">
							<template slot-scope="{ row }">
								<span>{{ row.task_sn }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="shop_name" label="店铺名称" width="200">
							<template slot-scope="{ row }">
								<span>{{ row.shop_name }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="area_name" label="商圈" min-width="80"></el-table-column>
						<el-table-column prop="task_name" label="任务名称" width="90">
							<template slot-scope="{ row }">
								<span>{{ row.task_name }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="staff_name" label="接单人" width="80">
							<template slot-scope="{ row }">
								<span>{{ row.staff_name }}</span>
							</template>
						</el-table-column>
						<el-table-column prop="hour_actual" label="实际时长" width="80"> </el-table-column>
						<el-table-column prop="shop_change_hour" label="店铺调整时长" width="70"> </el-table-column>
						<el-table-column prop="shop_change_settlement_amount" label="店铺调整时长金额" width="70">
						</el-table-column>
						<el-table-column prop="shop_change_other_amount" label="店铺其他金额" width="70"> </el-table-column>
						<el-table-column prop="shop_change_sum_amount" label="店铺调整合计金额" width="70"> </el-table-column>
						<el-table-column prop="staff_change_hour" label="人才调整时长" width="70"> </el-table-column>
						<el-table-column prop="staff_change_settlement_amount" label="人才调整时长金额" width="70">
						</el-table-column>
						<el-table-column prop="staff_change_other_amount" label="人才其他金额" width="70"> </el-table-column>
						<el-table-column prop="staff_change_sum_amount" label="人才调整合计金额" width="70"> </el-table-column>
						<el-table-column label="操作" min-width="80px" fixed="right">
							<template slot-scope="{ row }">
								<el-link :underline="false" type="success" class="InfoFont text-primary" @click="goTorecord(row)"
									>查看明细</el-link
								>
							</template>
						</el-table-column>
					</el-table>
					<!-- 分页组件 -->
					<page :total="total" :pageNums="pageNum" :disableMountedFetch="true" @pagedata="onChildValue"></page>
				</template>
			</div>
		</div>
		<!-- 创建调账记录-弹框 -->
		<el-dialog
			title="创建调账记录"
			:visible.sync="JobState"
			width="940px"
			:close-on-click-modal="false"
			:before-close="hiddenRY"
		>
			<div class="auditCentent tz">
				<div class="auditCentent_next">
					<div class="row-info clear">
						<div class="fl title-key"><i class="lhadmin lhadmin-wujiaoxing"></i>任务编号</div>
						<div class="fl list-cont bb">
							<el-input size="mini" placeholder="请填写" v-model="adjustment.task_sn" @blur="getTaskInfo()"></el-input>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">店铺名称</div>
						<div class="fl list-cont bb">
							<el-input size="mini" disabled v-model="adjustment.dpmc"></el-input>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">商圈</div>
						<div class="fl list-cont bb">
							<el-input size="mini" disabled v-model="adjustment.sq"></el-input>
						</div>
					</div>
				</div>
				<div class="auditCentent_next">
					<div class="row-info clear">
						<div class="fl title-key">岗位</div>
						<div class="fl list-cont bb">
							<el-input size="mini" disabled v-model="adjustment.gw"></el-input>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">工作时间</div>
						<div class="fl list-cont bb">
							<el-input size="mini" disabled v-model="adjustment.gzsj"></el-input>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">单价</div>
						<div class="fl list-cont bb">
							<el-input size="mini" disabled v-model="adjustment.dj"></el-input>
						</div>
					</div>
				</div>
				<div class="auditCentent_next">
					<div class="row-info clear">
						<div class="fl title-key">接单人</div>
						<div class="fl list-cont bb">
							<el-input size="mini" disabled v-model="adjustment.jdr"></el-input>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">实际时长</div>
						<div class="fl list-cont bb">
							<el-input size="mini" disabled v-model="adjustment.sjsc"></el-input>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">费用</div>
						<div class="fl list-cont bb">
							<el-input size="mini" disabled v-model="adjustment.fy"></el-input>
						</div>
					</div>
				</div>
				<div class="auditCentent_next">
					<div class="row-info clear">
						<div class="fl title-key">签到时间</div>
						<div class="fl list-cont bb">
							<el-input size="mini" disabled v-model="adjustment.qdsj"></el-input>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">完成时间</div>
						<div class="fl list-cont bb">
							<el-input size="mini" disabled v-model="adjustment.wcsj"></el-input>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">状态</div>
						<div class="fl list-cont bb">
							<el-input size="mini" disabled v-model="adjustment.zt"></el-input>
						</div>
					</div>
				</div>
				<!-- 历史调账记录 -->
				<el-table :data="recordsList" style="width: 100%;">
					<el-table-column prop="adjust_type" label="调账对象" align="center">
						<template slot-scope="{ row }">
							<span class="text-success" v-if="row.adjust_type == 'staff'">人才</span>
							<span class="text-info" v-if="row.adjust_type == 'shop'">店铺</span>
						</template>
					</el-table-column>
					<el-table-column prop="adjust_hours" label="调整时长" align="center">
						<template slot-scope="{ row }">
							<span>{{ row.adjust_hours }}h</span>
						</template>
					</el-table-column>
					<el-table-column prop="amount_other" label="其他金额" align="center"> </el-table-column>
					<el-table-column prop="adjust_amount" label="合计金额" align="center"> </el-table-column>
					<el-table-column prop="remark" label="备注" align="center"> </el-table-column>
					<el-table-column prop="status" label="状态" width="80" align="center">
						<template slot-scope="{ row }">
							<span class="text-light" v-if="row.status == 10">未入账单</span>
							<span class="text-primary" v-if="row.status == 20">已入账单</span>
							<span class="text-danger" v-if="row.status == 30">已作废</span>
							<span class="text-info" v-if="row.status == 40 && row.adjust_type == 'shop'">待支付</span>
							<span class="text-success" v-if="row.status == 50 && row.adjust_type == 'shop'">已支付</span>
							<span class="text-info" v-if="row.status == 40 && row.adjust_type == 'staff'">待提现</span>
							<span class="text-success" v-if="row.status == 50 && row.adjust_type == 'staff'">已提现</span>
							<span class="text-danger" v-if="row.status == 60">已退款</span>
						</template>
					</el-table-column>
					<el-table-column prop="adder" label="创建人" align="center"> </el-table-column>
					<el-table-column prop="add_time" label="创建时间" align="center" width="160"> </el-table-column>
				</el-table>
				<el-divider>对店铺{{ ' ' + adjustment.dj }}</el-divider>
				<div class="auditCentent_next">
					<div class="row-info clear">
						<div class="fl title-key">时长</div>
						<div class="fl list-cont shichang">
							<el-select v-model="adjustment.sc">
								<el-option label="加" value="1"></el-option>
								<el-option label="减" value="2"></el-option>
							</el-select>
							<el-input
								size="mini"
								v-model="adjustment.sc_next"
								onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false"
							></el-input>
							<div style="margin: 0 22px 0 0;">h</div>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">时长金额</div>
						<div class="fl list-cont shichang_next">
							<el-input size="mini" v-model="adjustment.scje" disabled></el-input>
							<div style="margin: 0 22px 0 0;">元</div>
						</div>
					</div>
				</div>
				<div class="auditCentent_next">
					<div class="row-info clear">
						<div class="fl title-key">其他金额</div>
						<div class="fl list-cont shichang">
							<el-select v-model="adjustment.qtje">
								<el-option label="加" value="1"></el-option>
								<el-option label="减" value="2"></el-option>
							</el-select>
							<el-input size="mini" v-model="adjustment.qtje_next"></el-input>
							<div style="margin: 0 16px 0 0;">元</div>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">合计金额</div>
						<div class="fl list-cont shichang_next">
							<el-input size="mini" v-model="adjustment.hjje" disabled></el-input>
							<div style="margin: 0 22px 0 0;">元</div>
						</div>
					</div>
				</div>
				<div class="auditCentent_next">
					<div class="row-info clear">
						<div class="fl title-key"><i class="lhadmin lhadmin-wujiaoxing"></i>备注</div>
						<div class="fl list-cont shichang">
							<el-input type="textarea" :rows="8" :cols="44" placeholder="请填写" v-model="adjustment.bz"></el-input>
						</div>
					</div>
				</div>
				<el-divider>对人才{{ ' ' + adjustment.personnel_dj }}</el-divider>
				<div class="auditCentent_next">
					<div class="row-info clear">
						<div class="fl title-key">时长</div>
						<div class="fl list-cont shichang">
							<el-select v-model="adjustment.personnel_sc">
								<el-option label="加" value="1"></el-option>
								<el-option label="减" value="2"></el-option>
							</el-select>
							<el-input
								size="mini"
								v-model="adjustment.personnel_sc_next"
								onKeyPress="if((event.keyCode<48 || event.keyCode>57) && event.keyCode!=46 || /\.\d\d$/.test(value))event.returnValue=false"
							></el-input>
							<div style="margin: 0 22px 0 0;">h</div>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">时长金额</div>
						<div class="fl list-cont shichang_next">
							<el-input size="mini" v-model="adjustment.personnel_scje" disabled></el-input>
							<div style="margin: 0 22px 0 0;">元</div>
						</div>
					</div>
				</div>
				<div class="auditCentent_next">
					<div class="row-info clear">
						<div class="fl title-key">其他金额</div>
						<div class="fl list-cont shichang">
							<el-select v-model="adjustment.personnel_qtje">
								<el-option label="加" value="1"></el-option>
								<el-option label="减" value="2"></el-option>
							</el-select>
							<el-input size="mini" v-model="adjustment.personnel_qtje_next"></el-input>
							<div style="margin: 0 16px 0 0;">元</div>
						</div>
					</div>
					<div class="row-info clear">
						<div class="fl title-key">合计金额</div>
						<div class="fl list-cont shichang_next">
							<el-input size="mini" v-model="adjustment.personnel_hjje" disabled></el-input>
							<div style="margin: 0 22px 0 0;">元</div>
						</div>
					</div>
				</div>
				<div class="auditCentent_next">
					<div class="row-info clear">
						<div class="fl title-key"><i class="lhadmin lhadmin-wujiaoxing"></i>备注</div>
						<div class="fl list-cont shichang">
							<el-input
								type="textarea"
								:rows="8"
								:cols="44"
								placeholder="请填写"
								v-model="adjustment.personnel_bz"
							></el-input>
						</div>
					</div>
				</div>
			</div>
			<div slot="footer" class="dialog-footer">
				<span class="btnOK mr_20" @click="ticketMesaudit()">保 存</span>
				<span class="resetBtn" @click="hiddenRY()">关 闭</span>
			</div>
		</el-dialog>
		<!-- 该任务已有调账记录，确认还要创建吗? -->
		<el-dialog title="创建提示" :visible.sync="AssignmentTips" width="560px" :close-on-click-modal="false">
			<div class="auditCentent">
				<span>该任务已有调账记录，确认还要创建吗?</span>
			</div>
			<div slot="footer" class="dialog-footer">
				<span class="btnOK mr_20" @click="ticketMesaudit(2)">确 定</span>
				<span class="resetBtn" @click="AssignmentTips = false">取 消</span>
			</div>
		</el-dialog>
	</div>
</template>

<script>
import { billCreate } from '@/api/bill'
var common = require('../../../static/tool.js')
import { fetchAreaList } from '@/api/shop.js'
export default {
	name: 'ShopMonitoring',
	data() {
		return {
			manageInfo: JSON.parse(sessionStorage.getItem('manageInfo')), //登录信息
			url: common.url,
			head_url: common.head_url,
			sn: '',
			message: '',
			//搜索对应值
			task_sn: '',
			shop_id: '', //店铺id
			shop_sn: '', //店铺sn
			shop_name: '', //店铺名
			staff_name: '', //接单人
			start_time: '', //任务开始时间
			end_time: '', //任务结束时间
			agent_id: '', //代理商

			adjustmentList: [], //调账列表
			//向分页组件传值
			total: 0,
			pageNum: 1,
			pageSizeNow: 20,
			shopList: [], //店铺列表
			JobState: false,
			AssignmentTips: false,
			//历史调账记录
			recordsList: [],

			//创建调账记录的值
			adjustment: {
				adjustment_sn: '', //调账记录编号
				task_sn: '', //任务编号
				dpmc: '', //店铺名称
				sq: '', //商圈
				gw: '', //岗位
				gzsj: '', //工作时间
				dj: '', //店铺单价
				personnel_dj: '', //人才单价
				jdr: '', //接单人
				sjsc: '', //实际时长
				fy: '', //费用
				qdsj: '', //签到时间
				wcsj: '', //完成时间
				zt: '', //状态
				//对店铺
				sc: '1', //时长
				sc_next: '0',
				scje: '0', //时长金额
				qtje: '1', //其他金额
				qtje_next: '0',
				hjje: '0', //合计金额
				bz: '', //备注
				//对人才
				personnel_sc: '1', //时长
				personnel_sc_next: '0',
				personnel_scje: '0', //时长金额
				personnel_qtje: '1', //其他金额
				personnel_qtje_next: '0',
				personnel_hjje: '0', //合计金额
				personnel_bz: '', //备注
				is_prepay: '', //是否预付
				invoice_status: '' //发票状态
			},

			cityList: [], //城市列表
			city_arr: '',
			city_id: '',
			city_name: '',
			city_val: '',
			areaList: [], //区域列表
			s_area_arr: '', //商圈信息
			s_area_id: '',
			s_area_name: '',
			areaStatus: true,

			agent_reset: 0
		}
	},
	computed: {
		//===对店铺===
		//时长金额计算
		scje() {
			const dj = this.adjustment.dj.substring(0, this.adjustment.dj.length - 4)

			if (this.adjustment.sc == 1) {
				return this.withhold2Pointer(this.adjustment.sc_next * dj)
			}

			return this.withhold2Pointer(this.adjustment.sc_next * dj * -1)
		},
		//合计金额计算
		hjje() {
			if (this.adjustment.qtje == 1) {
				return this.withhold2Pointer(this.adjustment.qtje_next * 1 + this.adjustment.scje * 1)
			}

			return this.withhold2Pointer(this.adjustment.qtje_next * -1 + this.adjustment.scje * 1)
		},

		//===对人才===
		//时长金额计算
		personnel_scje() {
			const dj = this.adjustment.personnel_dj.substring(0, this.adjustment.personnel_dj.length - 4)

			if (this.adjustment.personnel_sc == 1) {
				return this.withhold2Pointer(this.adjustment.personnel_sc_next * dj)
			}

			return this.withhold2Pointer(this.adjustment.personnel_sc_next * dj * -1)
		},
		//合计金额计算
		personnel_hjje() {
			if (this.adjustment.personnel_qtje == 1) {
				return this.withhold2Pointer(this.adjustment.personnel_qtje_next * 1 + this.adjustment.personnel_scje * 1)
			}

			return this.withhold2Pointer(this.adjustment.personnel_qtje_next * -1 + this.adjustment.personnel_scje * 1)
		},
		city_value() {
			return this.city_val
		}
	},
	watch: {
		//===对店铺===
		scje(newValue, oldValue) {
			if (!isNaN(newValue)) {
				this.adjustment.scje = newValue
			} else {
				this.adjustment.scje = 0
			}
		},
		hjje(newValue, oldValue) {
			if (!isNaN(newValue)) {
				this.adjustment.hjje = newValue
			} else {
				this.adjustment.hjje = 0
			}
		},
		//===对人才===
		personnel_scje(newValue, oldValue) {
			if (!isNaN(newValue)) {
				this.adjustment.personnel_scje = newValue
			} else {
				this.adjustment.personnel_scje = 0
			}
		},
		personnel_hjje(newValue, oldValue) {
			if (!isNaN(newValue)) {
				this.adjustment.personnel_hjje = newValue
			} else {
				this.adjustment.personnel_hjje = 0
			}
		},
		//商圈改变
		areaList(newValue, oldValue) {
			this.listShop()
		}
	},
	created() {},
	mounted() {},
	methods: {
		setValue(data) {
			this.agent_id = data.agent_id
			this.cityList = data.city_list
			if (this.cityList.length > 0) {
				this.city_val = this.cityList[0].name
				this.city_id = this.cityList[0].id
			}
			this.shop_id = ''
			this.shop_sn = ''
			this.shop_name = ''
			this.fetchAreaList() //商圈列表
			this.listUser() //店铺列表
		},
		listUser() {
			//获取商铺列表
			let fn = new FormData()
			fn.append('sign_status', 30) //已合作的店铺
			fn.append('status', 1) //启用的店铺
			fn.append('city_id', this.city_id)
			fn.append('agent_id', this.agent_id)
			this.$http.post(this.url + '/shop/getListForSearch', fn).then(
				res => {
					// console.log(res.data.data);
					if (res.data.msg == '查询成功' || res.data.code == '200') {
						if (res.data.data != null) {
							res.data.data.list.forEach(item => {
								item.value = item.name
							})
							this.shopList = res.data.data.list
						} else {
							this.shopList = []
						}
					} else if (res.data.code == '8886') {
						//code   8886  登录过期
						sessionStorage.clear()
						this.$alert('登录已过期，请重新登录 !', '提示', {
							confirmButtonText: '确定',
							callback: action => {
								window.location = 'login.html'
							}
						})
						return
					} else {
						this.$message.error(res.data.msg)
						return
					}
				},
				res => {
					this.$message.error('网络错误！')
					return
				}
			)
		},
		listShop() {
			var start_time = ''
			var end_time = ''
			if (this.start_time) {
				start_time = this.start_time + ' 00:00:00'
			}

			if (this.end_time) {
				end_time = this.end_time + ' 23:59:00'
			}

			let s_departmentIds_Arr = new Array()
			this.s_area_arr.forEach(element => {
				let [id, name] = element.split('|') // es6 数组解构赋值
				s_departmentIds_Arr.push(id.toString())
			})
			let fn = new FormData()
			fn.append('pageSize', this.pageSizeNow) //每页多少条
			fn.append('page', this.pageNum) //页数
			fn.append('city_id', this.city_id)
			fn.append('task_sn', this.task_sn)
			fn.append('area_id', '' + s_departmentIds_Arr)
			fn.append('shop_sn', this.shop_sn)
			fn.append('staff_name', this.staff_name)
			fn.append('start_time', start_time)
			fn.append('end_time', end_time)
			fn.append('agent_id', this.agent_id)
			this.$http.post(this.url + '/taskBillChange/getList', fn).then(
				res => {
					if (res.data.msg == '查询成功！' || res.data.code == '200') {
						if (res.data.data != null) {
							this.adjustmentList = res.data.data.list
							this.total = res.data.data.count
						} else {
							this.adjustmentList = []
							this.total = 0
						}
					} else if (res.data.code == '8886') {
						//code   8886  登录过期
						sessionStorage.clear()
						this.$alert('登录已过期，请重新登录 !', '提示', {
							confirmButtonText: '确定',
							callback: action => {
								window.location = 'login.html'
							}
						})
						return
					} else {
						this.$message.error(res.data.msg)
						return
					}
				},
				res => {
					this.$message.error('网络错误！')
					return
				}
			)
		},

		shearchBtn() {
			// 搜索
			this.pageNum = 1
			this.listShop()
		},

		async resetBtn() {
			//重置
			await this.resetData() //重置请求数据
		},

		async resetData() {
			//重置请求数据
			this.pageNum = 1
			this.sn = ''
			this.task_sn = ''
			this.business_id = '' //所属商户ID
			this.business_name = '' //所属商户name
			this.shop_id = '' //店铺id
			this.shop_sn = '' //店铺sn
			this.shop_name = '' //店铺名
			this.staff_name = '' //接单人
			this.start_time = ''
			this.end_time = ''

			// 重置代理商
			this.agent_reset += 1
		},
		//店铺的自动完成
		querySearch(queryString, cb) {
			var restaurants = this.shopList
			var results = queryString ? restaurants.filter(this.createFilter(queryString)) : restaurants
			// 调用 callback 返回建议列表的数据
			cb(results)
		},
		createFilter(queryString) {
			return restaurant => {
				return restaurant.value.toLowerCase().indexOf(queryString.toLowerCase()) === 0
			}
		},
		handleSelect(item) {
			console.log(item)
			this.shop_id = item.id
			this.shop_sn = item.shop_sn
		},
		//商户调账记录-导出
		downloadOrder() {
			var start_time = ''
			var end_time = ''
			if (this.start_time) {
				start_time = this.start_time + ' 00:00:00'
			}

			if (this.end_time) {
				end_time = this.end_time + ' 23:59:00'
			}

			let s_departmentIds_Arr = new Array()
			this.s_area_arr.forEach(element => {
				let [id, name] = element.split('|') // es6 数组解构赋值
				s_departmentIds_Arr.push(id.toString())
			})

			let obj = {
				token: JSON.parse(sessionStorage.getItem('manageInfo')).token,
				operation: 'export',
				task_sn: this.task_sn,
				city_id: this.city_id,
				area_id: '' + s_departmentIds_Arr,
				shop_name: this.shop_name,
				staff_name: this.staff_name,
				start_time: start_time,
				end_time: end_time,
				agent_id: this.agent_id
			}
			let param = $.param(obj)
			window.location.href = this.url + '/taskBillChange/getList?' + param
		},
		//分页组件->子组件传值
		onChildValue(item) {
			this.pageNum = item[0]
			this.pageSizeNow = item[1]
			this.listShop()
		},

		// 监听城市val变化
		changeCity() {
			let [id, name] = this.city_val.split('|') // es6 数组解构赋值
			this.city_id = id
			this.city_name = name
			this.shop_id = ''
			this.shop_sn = ''
			this.shop_name = ''

			this.fetchAreaList() //商圈列表
			this.listUser() //店铺列表
		},
		//获取商圈列表
		fetchAreaList() {
			this.s_area_arr = []
			let fn = new FormData()
			fn.append('city_id', this.city_id)
			fn.append('agent_id', this.agent_id)
			this.$http.post(this.url + '/area/list', fn).then(
				res => {
					if (res.data.msg == '查询成功' || res.data.code == '200') {
						if (res.data.data != null) {
							res.data.data.list.forEach(item => {
								item.value = item.area_name
							})
							this.areaList = res.data.data.list
							// if (this.s_area_arr == '' || this.s_area_arr == null) {
							// 	// 默认选中非254-平谷的
							// 	this.areaList.forEach(element => {
							// 		// 平谷
							// 		if (element.area_name != '平谷') {
							// 			var pusharr = element.id + '|' + element.area_name
							// 			this.s_area_arr.push(pusharr)
							// 		}
							// 	})
							// }
						} else {
							this.areaList = []
						}
					} else if (res.data.code == '8886') {
						//code   8886  登录过期
						sessionStorage.clear()
						this.$alert('登录已过期，请重新登录 !', '提示', {
							confirmButtonText: '确定',
							callback: action => {
								window.location = 'login.html'
							}
						})
						return
					} else {
						this.$message.error(res.data.msg)
						return
					}
				},
				res => {
					this.$message.error('网络错误！')
					return
				}
			)
		},
		//新增
		goToAdd(row) {
			this.JobState = true
		},
		getAdjustmentList() {
			let fn = new FormData()
			fn.append('task_sn', this.adjustment.task_sn)

			this.$http.post(this.url + '/billChange/getList', fn).then(
				res => {
					if (res.data.msg == '查询成功！' || res.data.code == '200') {
						if (res.data.data) {
							this.recordsList = res.data.data.list
						} else {
							this.recordsList = []
						}
					} else if (res.data.code == '8886') {
						//code   8886  登录过期
						sessionStorage.clear()
						this.$alert('登录已过期，请重新登录 !', '提示', {
							confirmButtonText: '确定',
							callback: action => {
								window.location = 'login.html'
							}
						})
						return
					} else {
						this.$message.error(res.data.msg)
						return
					}
				},
				res => {
					this.$message.error('网络错误！')
					return
				}
			)
		},
		//作废确认
		next() {
			//作废接口
			let fn = new FormData()
			fn.append('sn', this.sn)
			this.$http.post(this.url + '/billChange/invalid', fn).then(
				res => {
					if (res.data.msg == '查询成功' || res.data.code == '200') {
						this.$message.success(res.data.msg)
						this.hiddenRY()
						this.listShop()
					} else if (res.data.code == '8886') {
						//code   8886  登录过期
						sessionStorage.clear()
						this.$alert('登录已过期，请重新登录 !', '提示', {
							confirmButtonText: '确定',
							callback: action => {
								window.location = 'login.html'
							}
						})
						return
					} else {
						this.$message.error(res.data.msg)
						return
					}
				},
				res => {
					this.$message.error('网络错误！')
					return
				}
			)
		},
		// 操作记录
		goTorecord(row) {
			const { href } = this.$router.resolve({
				path: '/adjustmentList',
				query: {
					task_sn: row.task_sn
				}
			})
			window.open(href, '_blank')
		},
		getTaskInfo() {
			if (this.adjustment.task_sn != '') {
				//请求任务详情
				let fn = new FormData()
				fn.append('sn', this.adjustment.task_sn)
				this.$http.post(this.url + '/task/info', fn).then(
					res => {
						if (res.data.msg == '查询成功' || res.data.code == '200') {
							var task_info = res.data.data
							this.adjustment.dpmc = task_info.shop_name //店铺名称
							this.adjustment.sq = task_info.area_name //商圈
							this.adjustment.gw = task_info.job_name //岗位
							this.adjustment.gzsj = task_info.start_time.substr(11, 5) + ' - ' + task_info.end_time.substr(11, 5) //工作时间
							this.adjustment.dj = this.moneyUnitCent2Coin(task_info.amout_shop) + '元/小时' //店铺单价
							this.adjustment.personnel_dj = this.moneyUnitCent2Coin(task_info.amout_staff) + '元/小时' //人才单价
							this.adjustment.jdr = task_info.staff_name //接单人
							this.adjustment.sjsc = task_info.hour_actual + 'h' //实际时长
							this.adjustment.fy = this.moneyUnitCent2Coin(task_info.total_shop) + '元' //费用
							this.adjustment.qdsj = task_info.checkin_time //签到时间
							this.adjustment.wcsj = task_info.finish_time //完成时间
							this.adjustment.zt = task_info.status_name //状态
							this.adjustment.is_prepay = task_info.is_prepay //是否预付
							this.adjustment.invoice_status = task_info.invoice_status
							//获取历史调账记录
							this.getAdjustmentList()
						} else if (res.data.code == '8886') {
							//code   8886  登录过期
							sessionStorage.clear()
							this.$alert('登录已过期，请重新登录 !', '提示', {
								confirmButtonText: '确定',
								callback: action => {
									window.location = 'login.html'
								}
							})
							return
						} else {
							this.$message.error(res.data.msg)
							return
						}
					},
					res => {
						this.$message.error('网络错误！')
						return
					}
				)
			}
		},
		// 创建调账单
		async ticketMesaudit(e) {
			if (!this.adjustment.task_sn) {
				this.$message.error('请填写任务编号！')
				return
			}

			// shop
			let shop_obj
			if (this.adjustment.hjje != 0 && this.adjustment.bz) {
				shop_obj = {
					adjust_hours: this.adjustment.sc == 1 ? this.adjustment.sc_next * 1 : this.adjustment.sc_next * -1, //调整时长
					amount_hours: this.adjustment.scje, //时长金额
					amount_other: this.adjustment.qtje == 1 ? this.adjustment.qtje_next * 1 : this.adjustment.qtje_next * -1, //其他金额
					adjust_amount: this.adjustment.hjje, //合计金额
					remark: this.adjustment.bz //备注
				}
			} else if (this.adjustment.hjje == 0 && !this.adjustment.bz) {
				shop_obj = {}
			} else {
				this.$message.error('信息填写有误！')
				return
			}

			// staff
			let staff_obj
			if (this.adjustment.personnel_hjje != 0 && this.adjustment.personnel_bz) {
				staff_obj = {
					adjust_hours:
						this.adjustment.personnel_sc == 1
							? this.adjustment.personnel_sc_next * 1
							: this.adjustment.personnel_sc_next * -1, //调整时长
					amount_hours: this.adjustment.personnel_scje, //时长金额
					amount_other:
						this.adjustment.personnel_qtje == 1
							? this.adjustment.personnel_qtje_next * 1
							: this.adjustment.personnel_qtje_next * -1, //其他金额
					adjust_amount: this.adjustment.personnel_hjje, //合计金额
					remark: this.adjustment.personnel_bz //备注
				}
			} else if (this.adjustment.personnel_hjje == 0 && !this.adjustment.personnel_bz) {
				staff_obj = {}
			} else {
				this.$message.error('信息填写有误！')
				return
			}

			if (
				this.adjustment.hjje == 0 &&
				!this.adjustment.bz &&
				this.adjustment.personnel_hjje == 0 &&
				!this.adjustment.personnel_bz
			) {
				this.$message.error('信息填写有误！')
				return
			}
			// 是否是预付&&已开票&&负的调账，
			let isPrepay = this.adjustment.is_prepay
			let invoice_status = this.adjustment.invoice_status
			// console.log(isPrepay, invoice_status, this.adjustment.hjje, this.adjustment.personnel_hjje)
			if (invoice_status == 50 && isPrepay == 1 && (+this.adjustment.hjje < 0 || +this.adjustment.personnel_hjje < 0)) {
				let ret = await this.$alert('该任务已开发票，不允许创建退款调账', '提示', {
					confirmButtonText: '确定'
				})
				if (ret === 'confirm') return
			}

			let adjust = {
				task_sn: this.adjustment.task_sn,
				shop: JSON.stringify(shop_obj),
				staff: JSON.stringify(staff_obj)
			}

			if (e == 2) {
				adjust = {
					...adjust,
					force: 1
				}
			} else {
				let ret = await this.$confirm('确定要创建此调账吗？', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					type: 'warning'
				})
				if (ret === 'cancel') return
			}

			try {
				let ret = await billCreate(adjust)
				// console.log(ret)
				if (+ret.code === 601) {
					//强制确认的弹框出现
					this.AssignmentTips = true
					return
				}
				this.$message.success('创建调账单成功！')
				this.hiddenRY()
				this.listShop()
			} catch (err) {
				console.log(err)
			}
		},
		hiddenRY() {
			this.JobState = false
			this.AssignmentTips = false
			this.recordsList = []
			this.adjustment = {
				adjustment_sn: '', //调账记录编号
				task_sn: '', //任务编号
				dpmc: '', //店铺名称
				sq: '', //商圈
				gw: '', //岗位
				gzsj: '', //工作时间
				dj: '', //店铺单价
				personnel_dj: '', //人才单价
				jdr: '', //接单人
				sjsc: '', //实际时长
				fy: '', //费用
				qdsj: '', //签到时间
				wcsj: '', //完成时间
				zt: '', //状态
				sc: '1', //时长
				sc_next: '0',
				scje: '0', //时长金额
				qtje: '1', //其他金额
				qtje_next: '0',
				hjje: '0', //合计金额
				bz: '', //备注
				personnel_sc: '1', //时长
				personnel_sc_next: '0',
				personnel_scje: '0', //时长金额
				personnel_qtje: '1', //其他金额
				personnel_qtje_next: '0',
				personnel_hjje: '0', //合计金额
				personnel_bz: '', //备注
				is_prepay: '', //是否预付
				invoice_status: '' //发票状态
			}
		},
		//全选-取消全选商圈
		selectAllArea() {
			let arr = []
			this.areaList.forEach(item => {
				arr.push(`${item.id}|${item.area_name}`)
			})
			if (this.areaStatus == true) {
				this.s_area_arr = arr
			} else {
				this.s_area_arr = []
			}
			this.areaStatus = !this.areaStatus
			// this.shearchBtn()
		}
	}
}
</script>

<style scoped>
.auditCentent .labels {
	min-height: 100px;
}
.auditCentent .labels .labels_label {
	float: left;
	cursor: pointer;
}
.check_label {
	background: var(--purple4);
	color: #fff;
	border: none;
}
.pdf {
	width: 860px;
	height: 600px;
}
.main_user {
	background: var(--zfy-red);
	color: #fff;
	text-decoration: none;
	padding: 2px 4px;
	border-radius: 4px;
}

.auditCentent_next {
	display: flex;
	margin-bottom: 10px;
}

.timeline {
	height: 30px;
	line-height: 30px;
	margin-bottom: 20px;
}

.timeline span {
	margin-left: 10px;
}
</style>



// WEBPACK FOOTER //
// src/components/billshop/Adjustment.vue